home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d7 / laser.arc / LASER.C next >
C/C++ Source or Header  |  1992-01-14  |  6KB  |  301 lines

  1. /* laser.c
  2.  *
  3.  * Laser Disk Access Program
  4.  * runs on the pc that calls the laser disk
  5.  * by Patrick L. McGillan
  6.  *    University of Wisconsin - Superior
  7.  *
  8.  * with special thanks to Paul McGinnis, AST Research, Inc.
  9.  * whose programs on compuserve inspired these programs
  10.  *
  11.  */
  12.  
  13.  
  14. #include "netwrk.h"
  15.  
  16. struct REGPACK r;
  17.  
  18. struct {
  19.   int    length ;
  20.   char    function;
  21.   char    station ;
  22. } outpacket ;
  23.  
  24. struct {
  25.   int    length ;
  26.   char    uniqueid[4] ;
  27.   int    type ;
  28.   char    objectname[48] ;
  29.   char    logtime[8] ;
  30. } whoami ;
  31.  
  32. struct {
  33.   int    length ;
  34.   char    network[4] ;
  35.   char    host[6] ;
  36.   char    socket[2] ;
  37. } map ;
  38.  
  39.  
  40. main()
  41. {
  42.   int chr, done = 0;
  43.   char *fname, *direct;
  44.   char far * user_name;
  45.  
  46.   clrscr();
  47.  
  48.   system ("p:\\public\\netbios");
  49.  
  50.   block = (NCB far *) malloc(sizeof(NCB));
  51.   buf1 = (char far *) malloc(512);
  52.   buf2 = (char far *) malloc(512);
  53.   message = (char far *) malloc(80);
  54.   user_name = (char far *) malloc(16);
  55.  
  56.   printf ("\n\nLaser Disk Access Program");
  57.   printf ("\nby Patrick L. McGillan");
  58.   printf ("\n   University of Wisconsin - Superior");
  59.   printf ("\n\nGenerating your Network Name entry . . .");
  60.   get_user();
  61.   make_user();
  62.  
  63.   while (!done)
  64.   {
  65.     done = 1;
  66.  
  67.     printf ("\n\nNow I need two pieces of information . . .");
  68.  
  69.     printf ("\nFilename: ");  gets (fname);
  70.  
  71.     printf ("\nDirectory: "); gets (direct);
  72.  
  73.     strcpy (message, "c:\\");
  74.     if (strlen(direct) > 0)
  75.     {
  76.       strcat (message, direct);
  77.       strcat (message, "\\");
  78.     }
  79.     strcat (message, fname);
  80.  
  81.     call_user();
  82.  
  83.     send_fnam();
  84.  
  85.     recv_file(fname);
  86.  
  87.     printf ("\n\nCopy more files (y/n) <n> ");
  88.     if ((chr = toupper(getch())) == 'Y')
  89.       done = 0;
  90.  
  91.   }
  92.   delete_user();
  93. }
  94.  
  95.  
  96.  
  97. make_user()
  98. {
  99.   unsigned char ret_code;
  100.  
  101.   printf ("\nMaking: %s", whoami.objectname);
  102.  
  103.   block -> NCB_COMMAND = ADD_NAME_WAIT;   /* Use default time-out values */
  104.   block -> NCB_LANA_NUM = 0;
  105.   block -> NCB_STO = 0;
  106.   block -> NCB_RTO = 0;
  107.   strncpy(block -> NCB_NAME, whoami.objectname, 16);  /* Copy name to NCB   */
  108.   strncpy(block -> NCB_CALLNAME, "*", 16);  /* Check all names on net  */
  109.   _ES = FP_SEG(block);
  110.   _BX = FP_OFF(block);
  111.   _AX = 0x100;
  112.   geninterrupt(0x5c);
  113.   ret_code = _AL;
  114.   if ((ret_code) && (ret_code != 0x0d))
  115.     printf("\nBad return code = %02Xh", ret_code);
  116. }
  117.  
  118.  
  119.  
  120. delete_user()
  121. {
  122.   printf ("\n\nDeleting User name");
  123.   block -> NCB_COMMAND = DELETE_NAME_WAIT;
  124.   _ES = FP_SEG(block);
  125.   _BX = FP_OFF(block);
  126.   _AX = 0x100;
  127.   geninterrupt(0x5c);
  128. }
  129.  
  130.  
  131.  
  132. call_user()
  133. {
  134.   unsigned char ret_code;
  135.  
  136.   printf ("\n\nCalling User . . .");
  137.   block -> NCB_STO = 0;
  138.   strncpy(block -> NCB_CALLNAME, "Laser Disk", 16);
  139.   block -> NCB_COMMAND = CALL_WAIT;
  140.   _ES = FP_SEG(block);
  141.   _BX = FP_OFF(block);
  142.   _AX = 0x100;
  143.   geninterrupt(0x5c);
  144.   ret_code = _AL;
  145.   return (ret_code == 0x05);
  146. }
  147.  
  148.  
  149.  
  150. send_fnam()
  151. {
  152.   unsigned char ret_code;
  153.  
  154.   printf ("\n\nSending File Spec: %Fs", message);
  155.   block -> NCB_STO = 0;
  156.   block -> NCB_BUFFER_OFFSET = FP_OFF(message);
  157.   block -> NCB_BUFFER_SEGMENT = FP_SEG(message);
  158.   block -> NCB_LENGTH = strlen(message);
  159.   block -> NCB_COMMAND = SEND_WAIT;
  160.   _ES = FP_SEG(block);
  161.   _BX = FP_OFF(block);
  162.   _AX = 0x100;
  163.   geninterrupt(0x5c);
  164.   ret_code = _AL;
  165.   if (ret_code)
  166.   {
  167.     printf("\nError number = %02Xh", ret_code);
  168.     delete_user();
  169.   }
  170. }
  171.  
  172.  
  173.  
  174. wait()
  175. {
  176.     byte done;
  177.  
  178.     do
  179.     {
  180.         done = block->NCB_CMD_CPLT;
  181.         if (kbhit()) return(1);
  182.     } while (done == 0xff);
  183. }
  184.  
  185.  
  186. hang_up()
  187. {
  188.   block -> NCB_COMMAND = HANG_UP_WAIT;
  189.   _ES = FP_SEG(block);
  190.   _BX = FP_OFF(block);
  191.   _AX = 0x100;
  192.   geninterrupt(0x5c);
  193. }
  194.  
  195.  
  196. recv(buf)
  197. char far * buf;
  198. {
  199.   unsigned char ret_code;
  200.  
  201.   block -> NCB_STO = 0;
  202.   block -> NCB_BUFFER_OFFSET = FP_OFF(buf);
  203.   block -> NCB_BUFFER_SEGMENT = FP_SEG(buf);
  204.   block -> NCB_LENGTH = 512;
  205.   block -> NCB_COMMAND = RECEIVE_WAIT;
  206.   _ES = FP_SEG(block);
  207.   _BX = FP_OFF(block);
  208.   _AX = 0x100;
  209.   geninterrupt(0x5c);
  210.   ret_code = _AL;
  211.   return (ret_code);
  212. }
  213.  
  214.  
  215. recv_file(fname)
  216. char *fname;
  217. {
  218.   if ((disk = fopen(fname, "a+b")) == NULL)
  219.   {
  220.     printf ("\n\nERROR OPENING FILE: %s", fname);
  221.     hang_up();
  222.     return;
  223.   }
  224.  
  225.   printf ("\n\nLocal File: %s opened for writing", fname);
  226.   printf ("\nReceiving File ");
  227.   if (recv(buf1)) { close_file(); return; }
  228.  
  229.   while (1)
  230.   {
  231.     if (wait()) { close_file(); return; }
  232.     bytes = block->NCB_LENGTH;
  233.  
  234.     printf (".");
  235.  
  236.     if (bytes == 0) { close_file(); return; }
  237.     if (recv(buf2)) { close_file(); return; }
  238.     fwrite(buf1, bytes, 1, disk);
  239.     if (wait()) { close_file(); return; }
  240.     bytes = block->NCB_LENGTH;
  241.  
  242.     printf (".");
  243.  
  244.     if (bytes == 0) { close_file(); return; }
  245.     if (recv(buf1)) { close_file(); return; }
  246.     fwrite (buf2, bytes, 1, disk);
  247.   }
  248. }
  249.  
  250.  
  251. close_file()
  252. {
  253.   printf ("\n\n\nFile Transfer Complete!");
  254.   fclose(disk);
  255.   hang_up();
  256. }
  257.  
  258. /********************************************************************
  259.     WHO.C
  260.        Alternate menu function for Novell Netware
  261.  
  262.        First code : 10/13/87
  263.  
  264.     thanks to who ever put this on compuserve
  265.     used as a function to get a users login name
  266.  
  267. ********************************************************************/
  268.  
  269. get_user()
  270. {
  271.   int count,station,physical ;
  272.  
  273.   r.r_ds=_DS ;
  274.   r.r_es=_DS ;
  275.   r.r_ax=(0xdc00) ;
  276.   intr(0x21,&r) ;
  277.   station=(r.r_ax & 0xff) ;
  278.   r.r_ax=(0xee00) ;
  279.   intr(0x21,&r) ;
  280.   physical=r.r_ax ;
  281.   r.r_si=(int)&outpacket ;
  282.   r.r_di=(int)&whoami ;
  283.   r.r_ax= (0xe300) ;
  284.   whoami.length=sizeof(whoami) ;
  285.   outpacket.length=sizeof(outpacket) ;
  286.   outpacket.function=22 ;
  287.   outpacket.station=station ;
  288.   intr(0x21,&r) ;
  289.   r.r_si=(int)&outpacket ;
  290.   r.r_di=(int)&map ;
  291.   r.r_ax=0xe300 ;
  292.   outpacket.length=sizeof(outpacket) ;
  293.   outpacket.function=19 ;
  294.   outpacket.station=station ;
  295.   map.length=sizeof(map) ;
  296.   intr(0x21,&r) ;
  297.   physical=map.host[5] ;
  298.   printf("\nYou are user %s, at station %i, connection %i.\n",
  299.         whoami.objectname,station,physical) ;
  300. }
  301.